package hy.controller;

import hy.beans.Person;
import hy.util.YMLFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

@RestController
public class Demo2Ctrl {
    @Autowired
    @Qualifier("p1")
    Person p1;

    @Autowired
    @Qualifier("p2")
    Person p2;

    @Autowired
    Environment env;

    @Autowired
    YMLFactory y;

    @RequestMapping("/hello")
    public String hello(){
        return "世事多因忙中错，好人半自苦中来";
    }



    @RequestMapping("/load")
    public Person loadData() throws ParseException {
        p1.setAge(Integer.parseInt(env.getProperty("person.age")));
        p1.setBirth(new SimpleDateFormat("yyyy/MM/dd").parse(env.getProperty("person.birth")));
        System.out.println(p1);
        return p1;
    }


    @RequestMapping("/xmlData")
    public String getData(){
        System.out.println(p1);
        System.out.println(p2);
        System.out.println(p1==p2);
        //return y;
        return "success";
    }

}
